/*     */ package com.zimbra.cs.redolog.op;
/*     */ 
/*     */ import com.google.common.base.Strings;
/*     */ import com.zimbra.common.mailbox.Color;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.cs.mailbox.Folder.FolderOptions;
/*     */ import com.zimbra.cs.mailbox.MailItem.CustomMetadata;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.MailServiceException;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.mailbox.MailboxOperation;
/*     */ import com.zimbra.cs.redolog.RedoLogInput;
/*     */ import com.zimbra.cs.redolog.RedoLogOutput;
/*     */ import com.zimbra.cs.redolog.Version;
/*     */ import java.io.IOException;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class CreateFolderPath
/*     */   extends RedoableOp
/*     */ {
/*     */   private String path;
/*     */   private byte attrs;
/*     */   private MailItem.Type defaultView;
/*     */   private int flags;
/*     */   private long color;
/*     */   private String url;
/*     */   private Long date;
/*     */   private MailItem.CustomMetadata custom;
/*     */   private int[] folderIds;
/*     */   private String[] folderUuids;
/*     */   
/*     */   public CreateFolderPath()
/*     */   {
/*  51 */     super(MailboxOperation.CreateFolderPath);
/*     */   }
/*     */   
/*     */   public CreateFolderPath(int mailboxId, String path, Folder.FolderOptions fopt) {
/*  55 */     this();
/*  56 */     setMailboxId(mailboxId);
/*  57 */     this.path = (path == null ? "" : path);
/*  58 */     this.attrs = fopt.getAttributes();
/*  59 */     this.defaultView = fopt.getDefaultView();
/*  60 */     this.flags = fopt.getFlags();
/*  61 */     this.color = fopt.getColor().getValue();
/*  62 */     this.url = Strings.nullToEmpty(fopt.getUrl());
/*  63 */     this.date = fopt.getDate();
/*  64 */     this.custom = fopt.getCustomMetadata();
/*     */   }
/*     */   
/*     */   public int[] getFolderIds() {
/*  68 */     return this.folderIds;
/*     */   }
/*     */   
/*     */   public String[] getFolderUuids() {
/*  72 */     return this.folderUuids;
/*     */   }
/*     */   
/*     */   public void setFolderIdsAndUuids(int[] folderIds, String[] folderUuids) {
/*  76 */     this.folderIds = folderIds;
/*  77 */     this.folderUuids = folderUuids;
/*     */   }
/*     */   
/*     */   protected String getPrintableData()
/*     */   {
/*  82 */     StringBuilder sb = new StringBuilder("name=").append(this.path);
/*  83 */     sb.append(", attrs=").append(this.attrs).append(", view=").append(this.defaultView);
/*  84 */     sb.append(", flags=").append(this.flags).append(", color=").append(this.color);
/*  85 */     sb.append(", url=").append(this.url);
/*  86 */     sb.append(", date=").append(this.date);
/*  87 */     sb.append(", custom=").append(this.custom);
/*  88 */     if (this.folderIds != null) {
/*  89 */       sb.append(", folderIdsAndUuids=[");
/*  90 */       for (int i = 0; i < this.folderIds.length; i++) {
/*  91 */         sb.append(this.folderIds[i]).append(" (").append(this.folderUuids[i]).append(")");
/*  92 */         if (i < this.folderIds.length - 1) {
/*  93 */           sb.append(", ");
/*     */         }
/*     */       }
/*  96 */       sb.append("]");
/*     */     }
/*  98 */     return sb.toString();
/*     */   }
/*     */   
/*     */   protected void serializeData(RedoLogOutput out) throws IOException
/*     */   {
/* 103 */     out.writeUTF(this.path);
/* 104 */     out.writeByte(this.attrs);
/* 105 */     out.writeByte(this.defaultView.toByte());
/* 106 */     out.writeInt(this.flags);
/*     */     
/* 108 */     out.writeLong(this.color);
/* 109 */     out.writeUTF(this.url);
/*     */     
/* 111 */     out.writeBoolean(this.date != null);
/* 112 */     if (this.date != null) {
/* 113 */       out.writeLong(this.date.longValue());
/*     */     }
/*     */     
/* 116 */     if (this.custom == null) {
/* 117 */       out.writeUTF(null);
/*     */     } else {
/* 119 */       out.writeUTF(this.custom.getSectionKey());
/* 120 */       out.writeUTF(this.custom.getSerializedValue());
/*     */     }
/*     */     
/* 123 */     if (this.folderIds != null) {
/* 124 */       out.writeInt(this.folderIds.length);
/* 125 */       for (int i = 0; i < this.folderIds.length; i++) {
/* 126 */         out.writeInt(this.folderIds[i]);
/* 127 */         if (getVersion().atLeast(1, 37)) {
/* 128 */           out.writeUTF(this.folderUuids[i]);
/*     */         }
/*     */       }
/*     */     } else {
/* 132 */       out.writeInt(0);
/*     */     }
/*     */   }
/*     */   
/*     */   protected void deserializeData(RedoLogInput in) throws IOException
/*     */   {
/* 138 */     this.path = in.readUTF();
/* 139 */     this.attrs = in.readByte();
/* 140 */     this.defaultView = MailItem.Type.of(in.readByte());
/* 141 */     this.flags = in.readInt();
/* 142 */     if (getVersion().atLeast(1, 27)) {
/* 143 */       this.color = in.readLong();
/*     */     } else {
/* 145 */       this.color = in.readByte();
/*     */     }
/* 147 */     this.url = in.readUTF();
/* 148 */     if (getVersion().atLeast(1, 41)) {
/* 149 */       if (in.readBoolean()) {
/* 150 */         this.date = Long.valueOf(in.readLong());
/*     */       }
/* 152 */       String section = in.readUTF();
/* 153 */       if (section != null) {
/*     */         try {
/* 155 */           this.custom = new MailItem.CustomMetadata(section, in.readUTF());
/*     */         } catch (ServiceException e) {
/* 157 */           mLog.warn("could not deserialize custom metadata for folder", e);
/*     */         }
/*     */       }
/*     */     }
/*     */     
/* 162 */     int numParentIds = in.readInt();
/* 163 */     if (numParentIds > 0) {
/* 164 */       this.folderIds = new int[numParentIds];
/* 165 */       this.folderUuids = new String[numParentIds];
/* 166 */       for (int i = 0; i < numParentIds; i++) {
/* 167 */         this.folderIds[i] = in.readInt();
/* 168 */         if (getVersion().atLeast(1, 37)) {
/* 169 */           this.folderUuids[i] = in.readUTF();
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   public void redo() throws Exception
/*     */   {
/* 177 */     int mboxId = getMailboxId();
/* 178 */     Mailbox mailbox = MailboxManager.getInstance().getMailboxById(mboxId);
/*     */     
/* 180 */     Folder.FolderOptions fopt = new Folder.FolderOptions();
/* 181 */     fopt.setAttributes(this.attrs).setColor(Color.fromMetadata(this.color)).setDate(this.date);
/* 182 */     fopt.setDefaultView(this.defaultView).setFlags(this.flags).setUrl(this.url).setCustomMetadata(this.custom);
/*     */     try
/*     */     {
/* 185 */       mailbox.createFolder(getOperationContext(), this.path, fopt);
/*     */     } catch (MailServiceException e) {
/* 187 */       String code = e.getCode();
/* 188 */       if (code.equals("mail.ALREADY_EXISTS")) {
/* 189 */         mLog.info("Folder %s already exists in mailbox %d", new Object[] { this.path, Integer.valueOf(mboxId) });
/*     */       } else {
/* 191 */         throw e;
/*     */       }
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/redolog/op/CreateFolderPath.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */